﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cypher.Core.Configuration
{
	public sealed class CypherConfiguration : System.Configuration.ConfigurationSection
	{
		#region Fields

		private static readonly System.Configuration.ConfigurationProperty _providerType =
				new System.Configuration.ConfigurationProperty("providerType", typeof(string), string.Empty,
				System.Configuration.ConfigurationPropertyOptions.None);

		private static readonly System.Configuration.ConfigurationProperty _documentationfile =
				new System.Configuration.ConfigurationProperty("documentationfile", typeof(string), string.Empty,
				System.Configuration.ConfigurationPropertyOptions.None);

		private static readonly System.Configuration.ConfigurationProperty _services =
			new System.Configuration.ConfigurationProperty("services", typeof(ServiceElementCollection), null,
			System.Configuration.ConfigurationPropertyOptions.IsDefaultCollection| System.Configuration.ConfigurationPropertyOptions.IsRequired);

		//[System.Configuration.ConfigurationProperty("services", IsDefaultCollection = true, IsRequired = true)]

		//private static readonly ServiceElementCollection _services =
		//		new ServiceElementCollection();


		private static System.Configuration.ConfigurationPropertyCollection _properties;

		#endregion

		#region Constructor(s)

		public CypherConfiguration()
		{
			_properties = new System.Configuration.ConfigurationPropertyCollection();
			_properties.Add(_providerType);
			_properties.Add(_documentationfile);
			_properties.Add(_services);
		}

		#endregion

		#region Properties

		//[System.Configuration.ConfigurationProperty("providerType", IsRequired = false)]
		public string ProviderType
		{
			get
			{ return (string)this["providerType"]; }
			set
			{ this["providerType"] = value; }
		}

		//[System.Configuration.ConfigurationProperty("documentationfile", IsRequired = false)]
		public string Documentationfile
		{
			get
			{ return (string)this["documentationfile"]; }
			set
			{ this["documentationfile"] = value; }
		}

		[System.Configuration.ConfigurationProperty("services", IsDefaultCollection = true, IsRequired = true)]
		[System.Configuration.ConfigurationCollection(typeof(ServiceElementCollection), AddItemName = "service")]
		public ServiceElementCollection Services
		{
			get
			{
				return (ServiceElementCollection)this["services"];
			}
			set
			{ this["services"] = value; }
		}


		protected override System.Configuration.ConfigurationPropertyCollection Properties
		{
			get
			{
				return _properties;
			}
		}

		#endregion
	}
}
